package com.ledim.bean;

import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
import java.io.Serializable;
import java.util.ArrayList;
import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Id;
import org.greenrobot.greendao.annotation.Property;
import org.greenrobot.greendao.annotation.ToOne;
import org.greenrobot.greendao.annotation.Transient;
import org.greenrobot.greendao.annotation.Unique;
import org.greenrobot.greendao.annotation.Generated;
import org.greenrobot.greendao.DaoException;
import org.greenrobot.greendao.annotation.NotNull;
import com.ledim.db.dao.DaoSession;
import com.ledim.db.dao.ChatRoomBeanDao;
import com.ledim.db.dao.LedimPicBeanDao;
import com.ledim.db.dao.LedimUserBeanDao;

/**
 * Created by ccx on 16/6/22.
 * 首页放映厅bean
 */
@Entity(
        //  实体是否激活的标志，激活的实体有更新，删除和刷新的方法
        active = true,
        // 确定数据库中表的名称
        // 表名称默认是实体类的名称
        nameInDb = "ROOM")
public class ChatRoomBean implements Serializable {

    @Property(nameInDb = "Id")
    @Id(autoincrement = true)
    private Long id;

    @SerializedName("id")
    @Unique
    @Property(nameInDb = "room_id")
    public String roomId; // ID
    @Property(nameInDb = "name")
    public String name; // 名称
    @Property(nameInDb = "intro")
    public String intro; // 简介
    @Property(nameInDb = "status")
    public int status; // 房间状态

    @Property(nameInDb = "cover")
    private long coverId;
    @ToOne(joinProperty = "coverId")
    public LedimPicBean cover; // 封面

    @Property(nameInDb = "user")
    private long userId;
    @ToOne(joinProperty = "userId")
    public LedimUserBean user; // 房主信息

    @Property(nameInDb = "created_at")
    public String created_at; // 创建时间
    @Property(nameInDb = "time")
    public long time;
    @Transient
    public int cosplay;//非零为语C
    @Transient
    public String background;//语C背景
    @Transient
    public String current;
    @Transient
    public int announcement_type;
    @Transient
    public String announcement;
    @Transient
    public ArrayList<LedimChatMsgBean> history;//用于我的聊天室 消息轮询展示
    @Transient
    public int isChange;//关注列表发生变化  0不变化  1变化

    /**
     * Convenient call for {@link org.greenrobot.greendao.AbstractDao#refresh(Object)}.
     * Entity must attached to an entity context.
     */
    @Generated(hash = 1942392019)
    public void refresh() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.refresh(this);
    }

    /**
     * Convenient call for {@link org.greenrobot.greendao.AbstractDao#update(Object)}.
     * Entity must attached to an entity context.
     */
    @Generated(hash = 713229351)
    public void update() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.update(this);
    }

    /**
     * Convenient call for {@link org.greenrobot.greendao.AbstractDao#delete(Object)}.
     * Entity must attached to an entity context.
     */
    @Generated(hash = 128553479)
    public void delete() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.delete(this);
    }

    /** called by internal mechanisms, do not call yourself. */
    @Generated(hash = 235293986)
    public void setUser(@NotNull LedimUserBean user) {
        if (user == null) {
            throw new DaoException("To-one property 'userId' has not-null constraint; cannot set to-one to null");
        }
        synchronized (this) {
            this.user = user;
            userId = user.getId();
            user__resolvedKey = userId;
        }
    }

    /** To-one relationship, resolved on first access. */
    @Generated(hash = 1259414187)
    public LedimUserBean getUser() {
        long __key = this.userId;
        if (user__resolvedKey == null || !user__resolvedKey.equals(__key)) {
            final DaoSession daoSession = this.daoSession;
            if (daoSession == null) {
                throw new DaoException("Entity is detached from DAO context");
            }
            LedimUserBeanDao targetDao = daoSession.getLedimUserBeanDao();
            LedimUserBean userNew = targetDao.load(__key);
            synchronized (this) {
                user = userNew;
                user__resolvedKey = __key;
            }
        }
        return user;
    }

    @Generated(hash = 251390918)
    private transient Long user__resolvedKey;

    /** called by internal mechanisms, do not call yourself. */
    @Generated(hash = 220062289)
    public void setCover(@NotNull LedimPicBean cover) {
        if (cover == null) {
            throw new DaoException("To-one property 'coverId' has not-null constraint; cannot set to-one to null");
        }
        synchronized (this) {
            this.cover = cover;
            coverId = cover.getId();
            cover__resolvedKey = coverId;
        }
    }

    /** To-one relationship, resolved on first access. */
    @Generated(hash = 1760744950)
    public LedimPicBean getCover() {
        long __key = this.coverId;
        if (cover__resolvedKey == null || !cover__resolvedKey.equals(__key)) {
            final DaoSession daoSession = this.daoSession;
            if (daoSession == null) {
                throw new DaoException("Entity is detached from DAO context");
            }
            LedimPicBeanDao targetDao = daoSession.getLedimPicBeanDao();
            LedimPicBean coverNew = targetDao.load(__key);
            synchronized (this) {
                cover = coverNew;
                cover__resolvedKey = __key;
            }
        }
        return cover;
    }

    @Generated(hash = 1608555099)
    private transient Long cover__resolvedKey;
    /** Used for active entity operations. */
    @Generated(hash = 1408115144)
    private transient ChatRoomBeanDao myDao;

    /** Used to resolve relations */
    @Generated(hash = 2040040024)
    private transient DaoSession daoSession;

    public long getTime() {
        return this.time;
    }

    public void setTime(long time) {
        this.time = time;
    }

    public String getCreated_at() {
        return this.created_at;
    }

    public void setCreated_at(String created_at) {
        this.created_at = created_at;
    }

    public long getUserId() {
        return this.userId;
    }

    public void setUserId(long userId) {
        this.userId = userId;
    }

    public long getCoverId() {
        return this.coverId;
    }

    public void setCoverId(long coverId) {
        this.coverId = coverId;
    }

    public int getStatus() {
        return this.status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public String getIntro() {
        return this.intro;
    }

    public void setIntro(String intro) {
        this.intro = intro;
    }

    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getRoomId() {
        return this.roomId;
    }

    public void setRoomId(String roomId) {
        this.roomId = roomId;
    }

    public Long getId() {
        return this.id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    /** called by internal mechanisms, do not call yourself. */
    @Generated(hash = 1256359821)
    public void __setDaoSession(DaoSession daoSession) {
        this.daoSession = daoSession;
        myDao = daoSession != null ? daoSession.getChatRoomBeanDao() : null;
    }

    @Generated(hash = 163879643)
    public ChatRoomBean(Long id, String roomId, String name, String intro, int status, long coverId,
                        long userId, String created_at, long time) {
        this.id = id;
        this.roomId = roomId;
        this.name = name;
        this.intro = intro;
        this.status = status;
        this.coverId = coverId;
        this.userId = userId;
        this.created_at = created_at;
        this.time = time;
    }

    @Generated(hash = 2079157416)
    public ChatRoomBean() {
    }
}
